<html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">
dt {
  font-style: italic;
  margin-top: 15px;
  margin-bottom: 3px;
  margin-left: 0px;
  border-bottom: 1px dotted black;
}
dd {
  margin-left: 10px;
}
table {
  border-collapse:collapse;
  border: 1px solid black;
  margin-top: 7px;
}
th {
  border: 1px solid black;
  padding: 3 7 3 7;
}
td {
  border: 1px solid black;
  padding: 3 7 3 7;
}
</style></head><body><p><a name="new"></a><b>new</b> :
  create an object : <a href="opcodes.html">index</a> : <a href="http://asm.objectweb.org/asm40/javadoc/user/org/objectweb/asm/MethodVisitor.html#visitIntInsn(int,%20int)">visitIntInsn()</a></p><dl><dt>Description</dt><dd>new is used to create object instances. <br></br>new takes a single parameter, &lt;class&gt;, the name of the class of
object you want to create. &lt;class&gt; is resolved into a Java class (see
Chapter 7 for a discussion of how classes are resolved).  Then new
determines the size in bytes of instances of  the given class and allocates
memory for the new instance from the garbage collected heap. The fields of the
instance are set to the initial value 0 (for numeric and boolean fields), or
null (for reference fields).  Next, a reference to the new object is
pushed onto the operand stack.<br></br>Note that the new object is initialize uninitialized - before the new object
can be used, one of its &lt;init&gt; methods must be called using
invokespecial, as shown in the example below.</dd><dt>Exceptions</dt><dd>OutOfMemoryError - not enough memory to allocate a new instance<br></br>InstantiationError - The class named by &lt;type&gt; is an abstract
class or an interface</dd><dt>Example</dt><dd><pre>
; This example creates a new StringBuffer object. This is like the Java code:
;
;    StringBuffer x = new StringBuffer();
; 1. use new to create a new object reference
new java/lang/StringBuffer
; 2. dup the object reference and call its constructor
dup
invokespecial java/lang/StringBuffer/&lt;init&gt;()V
; 3. assign object reference on the stack to a local variable
astore_1
; local variable 1 now contains a StringBuffer object,
; ready for use

; the following example shows how to call a non-default
; constructor. It is like the Java code:
;
;    StringBuffer x = new StringBuffer(100);
new java/lang/StringBuffer
dup
bipush 100
invokespecial java/lang/StringBuffer/&lt;init&gt;(I)V
astore_1
</pre></dd><dt>See also</dt><dd><a href="ref-anewarray.html">anewarray</a> <a href="ref-.html"></a> <a href="ref-newarray.html">newarray</a> <a href="ref-.html"></a> <a href="ref-multianewarray.html">multianewarray</a> </dd><dt>Stack</dt><dd><table xmlns="">
<tr>
<td>
<b>Before </b>
</td>
<td><b>After</b></td></tr>
<tr>
<td>...</td>
<td>objectref</td></tr>
<tr>
<td></td>
<td>...</td></tr>
</table></dd><dt>Bytecode</dt><dd><table xmlns="">
<tr>
<td>
<b> Type </b>
</td>
<td><b>Description</b></td></tr>
<tr>
<td>
u1 
</td>
<td>new
opcode = 0xBB (187)
</td></tr>
<tr>
<td>
u2 
</td>
<td>index</td></tr>
</table></dd></dl></body></html>